package tables

import (
	"peilian-api/app/global/variable"

	"gorm.io/gorm"
)

type SpecialQuestion struct {
	gorm.Model
	QuestionID   int64    `gorm:"primaryKey;comment:问题id" json:"question_id"`
	FrontShowTag string   `gorm:"primaryKey;comment:前端展示标签" json:"front_show_tag"`
	Criteria     string   `gorm:"size:255;not null;comment:能力标签(专项练习算法使用)" json:"criteria"`
	Level        string   `gorm:"size:255;not null;comment:级别" json:"level [基础|进阶]"`
	CareerID     int64    `gorm:"type:bigint(20);not null;comment:职位id" json:"career_id"`
	Question     Question `gorm:"foreignkey:QuestionID"`
}

func (SpecialQuestion) TableName() string {
	return "special_question"
}

func (s *SpecialQuestion) GetListByWhere(whereStr string, whereMap map[string]interface{}) ([]SpecialQuestion, error) {
	var sq []SpecialQuestion
	if len(whereStr) != 0 && len(whereMap) != 0 {
		d := variable.DB.MySQL.Model(&s).Preload("Question").Where(whereStr).Where(whereMap).Find(&sq)
		return sq, d.Error
	} else if len(whereStr) != 0 {
		d := variable.DB.MySQL.Model(&s).Preload("Question").Where(whereStr).Find(&sq)
		return sq, d.Error
	} else if len(whereMap) != 0 {
		d := variable.DB.MySQL.Model(&s).Preload("Question").Where(whereMap).Find(&sq)
		return sq, d.Error
	}
	return sq, nil
}
